Nullish Coalescing
https://devblogs.microsoft.com/typescript/announcing-typescript-3-7/#nullish-coalescing
code:ts
let x = foo ?? bar();
// the above code is equivalent to the following.
let x = (foo !== null && foo !== undefined) ?
foo :
bar();
Optional Chainingと合わせて
code:before.ts
// いままで
// nullrableなbarがあり、barの子要素を取得したいとき
const bar = foo.bar!;
const baz = bar.baz ? bar.baz : null;
// これから
const bar = foo?.bar ?? null;
// fooがnullなら undefined ?? null -> null
// barがnullなら undefined ?? null -> null